package com.hyt.it.ogt.kq.service.gov.schedule.utils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.hyt.it.ogt.kq.service.gov.schedule.model.Candidate;
import com.hyt.it.ogt.kq.service.gov.schedule.model.ExamInfo;
import com.hyt.it.ogt.kq.service.gov.schedule.model.ScheduleResult;
import com.hyt.it.ogt.kq.service.gov.schedule.model.ScheduleExamRoom.ScheduleCandidate;

public class ScheduleValidUtils {
    // 验证编排的学生在对应的批次里面
    public static void validScheduleCandidateInExamInfo(List<ScheduleResult> scheduleResults,
            List<ExamInfo> examInfos) {
        Map<String, ExamInfo> examInfoMap = examInfos.stream()
                .collect(Collectors.toMap(ExamInfo::getBatchId, item -> item));
        scheduleResults.stream().forEach(item -> {
            Map<String, Candidate> candidateMap = ScheduleUtils.getExamCandidateMap(examInfoMap.get(item.getBatchNo()));

            List<ScheduleCandidate> scheduleCandidates = ScheduleUtils.getScheduledCandidates(item);
            scheduleCandidates.stream().forEach(scandidate -> {
                if (!candidateMap.containsKey(scandidate.getBmStudentId())) {
                    throw new RuntimeException(
                            "编排错误: 已编排考生ID " + scandidate.getBmStudentId() + "不在该批次 " + item.getBatchNo() + "考生列表里面");
                }
            });
        });
    }
}
